<?php
/**
 * Created by PhpStorm
 * User: whh
 * Date: 2022/12/6
 * Time: 10:08
 */

namespace app\common\command;

use app\common\classes\VoucherRedis;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\Db;

class Hello extends Command
{
    protected function configure()
    {
        $this->setName('hello')
            ->addArgument('action', Argument::OPTIONAL, "方法名称")
            ->setDescription('测试任务');
    }

    protected function execute(Input $input, Output $output)
    {   $action = $input->getArgument('action');
        $this->$action();
    }

    /*批量设置扣量规则*/
    public function kl(){
        $channels = Db::table("cms_manager_user")->where("role_id",9)->where("parent_id","<>",88)->field("id,parent_id")->select();
//        foreach ($channels as $channel){
//            $save = [];
//            $save['agent_id'] = $channel['parent_id'];
//            $save['channel_id'] = $channel['id'];
//            $save['odds'] = 0.20;
//            $save['switch'] = 1;
//            $save['user_group'] = 1;
//            $save['login_judg'] = 0;
//            $save['login_hour'] = 2;
//            $save['register_judg'] = 1;
//            $save['register_day'] = 7;
//            $id = Db::table("pay_order_kl_config")->where("channel_id",$channel['id'])->value('id');
//            if ($id){
//                Db::table("pay_order_kl_config")->where("channel_id",$channel['id'])->update($save);
//            }else{
//                Db::table("pay_order_kl_config")->insert($save);
//            }
//        }
    }

    /*批量授权快应用*/
    public function sqQuick(){
        $uidArr = [2870,2881,2883,2884,2885,2890,2908,2924,2937,2938,2941,2943,2944,2946,2947,2948,2949,2950,2951,2952];
        $qidArr = [13,14,15,16];
//        foreach ($uidArr as $uid){
//            $where = [];
//            $where[] = ['uid','=',$uid];
//            foreach ($qidArr as $qid){
//                $where[] = ['quick_id','=',$qid];
//                $have = Db::table("quick_app_mp_manager")->where($where)->find();
//                if (!$have){
//                    Db::table("quick_app_mp_manager")->insert([
//                        'uid' => $uid,
//                        'quick_id' => $qid
//                    ]);
//                }
//            }
//        }
    }

    /**
     * 删除消费凭证
     */
    public function delReadVoucher(){
        $obj = new VoucherRedis();
        $obj->delReadVoucher();
    }

//    public function runpay(){
//        ini_set ('memory_limit', "-1") ;
//        $uidArr = Db::table("pay_order")->where("status",2)->column('uid');
//        $uidArr2 = Db::table("pay_order_kl_backups")->where("status",2)->column('uid');
//        $mUser = array_merge($uidArr,$uidArr2);
//        $mUser = array_unique($mUser);
//        $mUser = array_reverse($mUser);
//        foreach ($mUser as $k => $v){
//            $id = Db::table("quick_pay_user_record")->where("uid",$v)->value('id');
//            $money1 = Db::table("pay_order")->where("status",2)->where("uid",$v)->sum('total_fee') ?? 0;
//            $money2 = Db::table("pay_order_kl_backups")->where("status",2)->where("uid",$v)->sum('total_fee') ?? 0;
//
//            $count1 = Db::table("pay_order")->where("status",2)->where("uid",$v)->count();
//            $count2 = Db::table("pay_order_kl_backups")->where("status",2)->where("uid",$v)->count();
//            $save = [
//                'uid' => $v,
//                'pay_money' => $money1 + $money2,
//                'pay_num' => $count1 + $count2,
//            ];
//            if ($id){
//                Db::table("quick_pay_user_record")->where("uid", $v)->update($save);
//            }else{
//                Db::table("quick_pay_user_record")->insert($save);
//            }
//            echo $k.PHP_EOL;
//        }
//    }

}